Python is widely used general-purpose high-level programming language. Its design philosophy emphasizes code readability. It is very popular in science.
The Jupyter Notebook is a web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text.
This is Markdown cell
In [1]:
print('This is cell with code')
In [ ]:
In [2]:
var1 = 1
my_string = "This is a string"
In [3]:
var1
Out[3]:
In [4]:
print(my_string)
In [5]:
my_list = [1, 2, 3, 'x', 'y']
my_list
Out[5]:
In [6]:
my_list[0]
Out[6]:
In [7]:
my_list[1:3]
Out[7]:
In [8]:
salaries = {'Mike':2000, 'Ann':3000}
In [9]:
salaries['Mike']
Out[9]:
In [10]:
salaries['Jake'] = 2500
In [11]:
salaries
Out[11]:
In [12]:
long_string = 'This is a string \n Second line of the string'
In [13]:
print(long_string)
In [14]:
long_string.split(" ")
Out[14]:
In [15]:
long_string.split("\n")
Out[15]:
In [16]:
long_string.count('s') # case sensitive!
Out[16]:
In [17]:
long_string.upper()
Out[17]:
In [18]:
if long_string.startswith('X'):
print('Yes')
elif long_string.startswith('T'):
print('It has T')
else:
print('No')
In [19]:
for line in long_string.split('\n'):
print line
In [20]:
c = 0
while c < 10:
c += 2
print c
In [21]:
some_numbers = [1,2,3,4]
In [22]:
[x**2 for x in some_numbers]
Out[22]:
In [23]:
with open('../README.md', 'r') as f:
content = f.read()
In [24]:
print(content)
In [25]:
def average(numbers):
return float(sum(numbers)/len(numbers))
In [26]:
average([1,2,2,2.5,3,])
Out[26]:
In [27]:
map(average, [[1,2,2,2.5,3,],[3,2.3,4.2,2.5,5,]])
Out[27]:
In [28]:
# %load cool_events.py
#!/usr/bin/env python
from IPython.display import HTML
class HUB:
"""
HUB event class
"""
def __init__(self, version):
self.full_name = "Heidelberg Unseminars in Bioinformatics"
self.info = HTML("<p>Heidelberg Unseminars in Bioinformatics are participant-"
"driven meetings where people with an interest in bioinformatics "
"come together to discuss hot topics and exchange ideas and then go "
"for a drink and a snack afterwards.</p>")
self.version = version
def __repr__(self):
return self.full_name
In [29]:
this_event = HUB(21)
In [30]:
this_event
Out[30]:
In [31]:
this_event.full_name
Out[31]:
In [32]:
this_event.version
Out[32]:
Library is a collection of resources. These include pre-written code, subroutines, classes, etc.
In [33]:
from math import exp
In [34]:
exp(2) #shift tab to access documentation
Out[34]:
In [35]:
import math
In [36]:
math.exp(10)
Out[36]:
In [37]:
import numpy as np # Numpy - package for scientifc computing
In [38]:
#import pandas as pd # Pandas - package for working with data frames (tables)
In [39]:
#import Bio # BioPython - package for bioinformatics
In [40]:
#import sklearn # scikit-learn - package for machine larning
In [41]:
#from rdkit import Chem # RDKit - Chemoinformatics library
In [42]:
%matplotlib inline
In [43]:
import matplotlib.pyplot as plt
In [44]:
x_values = np.arange(0, 20, 0.1)
y_values = [math.sin(x) for x in x_values]
In [45]:
plt.plot(x_values, y_values)
Out[45]:
In [46]:
plt.scatter(x_values, y_values)
Out[46]:
In [47]:
plt.boxplot(y_values)
Out[47]:
In [ ]: